package com.lagou.mr.number_sort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class NumberSortMapper extends Mapper<LongWritable, Text, NumberBean, NullWritable> {

    NumberBean bean = new NumberBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 读取一行文本，转为字符串，切分
        String[] fields = value.toString().split("\t");
        // 解析出字段封装成NumberBean
        bean.setNumber(Integer.parseInt(fields[0]));
        // NumberBean作为key输出
        context.write(bean, NullWritable.get());
    }
}
